package com.practice;

import java.util.Random;

public class CheckCode {
    public static void main(String[] args) {
        //验证码 前4个为字母 最后1个为数字
        //用数组存放所有字母  利用随机数选择产生字母
        char[] Alphabet=new char[52];
        for (int i = 0; i < Alphabet.length; i++) {
            if (i<=26){
                Alphabet[i]=(char) ('a'+i);
            }else Alphabet[i]=(char) ('A'+i-26);
        }
        /*for (int i = 0; i < Alphabet.length; i++) {
            System.out.println(Alphabet[i]);
        }*/
        Random r=new Random();
        String key="";
        //选取4位字母
        for (int i = 0; i < 4; i++) {
            int randomKey=r.nextInt(Alphabet.length);
            key=key+Alphabet[randomKey];
        }
        int num=r.nextInt(10);
        key+=num;
        System.out.println(key);
    }
}
